<template>
  <a-modal
    width="800px"
    :bodyStyle="{ height: '500px', overflow: 'auto' }"
    title="答复确认"
    :visible="modalVisible"
    :footer="null"
    @cancel="handleCancel"
  >
    <a-form-model ref="inform" :rules="rules" :model="infoForm">
      <a-form-model-item
        v-for="item in items"
        :key="item.value"
        :label-col="item.labelCol"
        :wrapper-col="item.wrapperCol"
        :label="item.label"
        :prop="item.key"
        has-feedback
      >
        <a-input
          v-if="item.type == 'input'"
          v-model="infoForm[item.key]"
          allow-clear
          :disabled="item.config.disabled"
          :placeholder="item.placeholder"
        />
        <a-textarea
          v-if="item.type == 'textarea'"
          v-model="infoForm[item.key]"
          :disabled="item.config.disabled"
          :placeholder="item.placeholder"
        />
        <a-select
          v-if="item.type == 'select'"
          allow-clear
          :placeholder="item.placeholder"
          :mode="item.config.mode"
          v-model="infoForm[item.key]"
          :disabled="item.config.disabled"
        >
          <a-select-option v-for="selectItem in item.config.options" :key="selectItem.value">
            {{ selectItem.name }}
          </a-select-option>
        </a-select>
        <a-date-picker
          v-if="item.type == 'date'"
          v-model="infoForm[item.key]"
          :disabled="item.config.disabled"
          show-time
          :format="item.config.format"
          :placeholder="item.placeholder"
          :allowClear="true"
        />
      </a-form-model-item>
      <a-form-model-item>
        <div class="text-center">
          <a-button class="m-r-8" icon="reload" @click="handleCancel"> 取消 </a-button>
          <a-button type="primary" @click="onSubmit" icon="save" :loading="loading"> 提交 </a-button>
        </div>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>
import { updateTargetReply } from '@/api/accept/apl_admreview'
export default {
  props: {
    items: {
      type: Array,
      required: true
    },
    applyid: {
      type: String,
      required: true
    },
    busiName: {
      type: String,
      required: true
    },
  },
  data() {
    return {
      loading: false, //按钮显示
      modalVisible: false, //模态框显示
      infoForm: {},
      rules: {},
    }
  },
  created() {},
  methods: {
    handleCancel() {
      this.modalVisible = false
    },
    initFormAndRule() {
      this.infoForm = {}
      this.rules = {}
      if (this.busiName != 'hear_reply') {
        this.modalVisible = true
        for (let item of this.items) {
          // this.infoForm[item.key]  = undefined;
          // 使用set设置 而不能直接设置值
          this.$set(this.infoForm, item.key, undefined)
          if (item.required) {
            let message = ''
            if (item.type == 'input' || item.type == 'textarea') {
              message = '请输入' + item.label
              this.rules[item.key] = [{ required: true, message: message, trigger: 'blur' }]
            }
            if (item.type == 'select' || item.type == 'date') {
              message = '请选择' + item.label
              this.rules[item.key] = [{ required: true, message: message, trigger: 'change' }]
            }
          }
        }
      } else if (this.busiName === 'hear_reply') {
        this.modalVisible = false
        this.$confirm({
          title: '提示',
          content: '是否同意被申请人答复',
          onOk: () => {
            // 通过applyid 更新数据
            this.updateTargetReply(true)
          },
          onCancel: () => {
            this.updateTargetReply(false)
          }
        })
      }
    },
    updateTargetReply(status) {
      updateTargetReply({ applyid: this.applyid, reply: status }).then((res) => {
        if (res.code == 0) {
          this.$message.success('更新被申请人答复状态成功')
        } else {
          this.$message.error('更新被申请人答复状态失败')
        }
      })
    },
    resetForm() {
      this.initFormAndRule()
    },
    /**
     * 提交表单
     */
    onSubmit() {
    },
  },
}
</script>

<style lang="scss" scoped></style>
    